package script.grammar.symbol;

public class ArrayType implements Type {
	private Type elementType;
	private TypeSymbol symbol;
	
	public ArrayType(Type elementType) {
		this.elementType = elementType;
		this.symbol = new TypeSymbol(getName(), this);
	}
	
	public Type getElementType() {
		return elementType;
	}

	@Override
	public String getName() {
		return elementType.getName() + "[]";
	}
	
	@Override
	public String getAlias() {
		return "List<" + elementType.getAlias() + ">";
	}

	@Override
	public int getIndex() {
		return NativeType.OBJECT.getIndex();
	}
	
	@Override
	public Symbol getTypeSymbol() {
		return symbol;
	}
	
	@Override
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		if (!o.getClass().equals(getClass())) {
			return false;
		}
		
		return ((ArrayType)o).getElementType().equals(getElementType());
	}
	
	@Override
	public int hashCode() {
		return ~getElementType().hashCode();
	}
}
